// const AutoImport = require('unplugin-auto-import/webpack')
// const Components = require('unplugin-vue-components/webpack')
// const { ElementPlusResolver } = require('unplugin-vue-components/resolvers')
const subprojectProxy = require('./subproject-proxy')
const IS_PROD = ['production', 'prod'].includes(process.env.NODE_ENV)

module.exports = {
  publicPath: process.env.BASE_URL,
  devServer: {
    port: '7000',
    proxy: {
      // 子项目文件请求代理
      ...subprojectProxy,
      '/hrplat': {
        target: process.env.VUE_APP_API_URL,
        changeOrigin: true // 本地就会虚拟一个服务器接收你的请求并代发送请求
      }
    }
  },
  lintOnSave: false,
  configureWebpack: {
    plugins: [
      // AutoImport({
      //   resolvers: [ElementPlusResolver()]
      // }),
      // Components({
      //   resolvers: [ElementPlusResolver()]
      // })
    ]
  },
  productionSourceMap: !IS_PROD, // 生产环境的 source map
  chainWebpack: (config) => {
    // config.module
    //   .rule('vue')
    //   .use('vue-loader')
    //   .tap((options) => {
    //     // 修改它的选项...
    //     return options
    //   })

    // 移除 prefetch 插件
    config.plugins.delete('prefetch')
    config.when(process.env.NODE_ENV !== 'development', (config) => {
      config.optimization.minimizer('terser').tap((options) => {
        // options[0].terserOptions.compress.drop_console = true;
        return options
      })
    })
    config.optimization.splitChunks({
      chunks: 'all',
      cacheGroups: {
        libs: {
          name: 'libs',
          test: /[\\/]node_modules[\\/]/,
          priority: 10,
          chunks: 'initial'
        },
        ElementPlus: {
          name: 'element-plus',
          test: /[\\/]node_modules[\\/]_?element-plus(.*)/,
          priority: 20
        },
        vue: {
          name: 'vue',
          test: /[\\/]node_modules[\\/]_?vue(.*)/,
          priority: 30
        }
        // axios: {
        //   name: 'axios',
        //   test: /[\\/]node_modules[\\/]_?axios(.*)/,
        //   priority: 60
        // }
        // commons: {
        //   name: 'chunk-commons',
        //   // test: resolve('src/components'),
        //   minChunks: 3,
        //   priority: 5,
        //   reuseExistingChunk: true
        // }
      }
    })
  }
}
